<template>
  <div class="container">
    <div class="app-container">
      <div class="left">
        <el-input style="margin-bottom:10px" type="text" prefix-icon="el-icon-search" size="small" placeholder="输入员工姓名全员搜索" />
        <!-- 树形组件 -->
        <el-tree :data="depts" :props="defaultProps" @node-click="setid" />
      </div>
      <div class="right">
        <el-row class="opeate-tools" type="flex" justify="end">
          <el-button size="mini" type="primary">添加员工</el-button>
          <el-button size="mini">excel导入</el-button>
          <el-button size="mini">excel导出</el-button>
        </el-row>
        <!-- 表格组件 -->

        <el-table
          :data="list"
        >
          <el-table-column
            prop="staffPhoto"
            label="头像"
          >
            <template #default="{ row }">
              <img
                ref:img
                class="avator"
                :src="row.staffPhoto"
              >
            </template>
          </el-table-column>
          <el-table-column
            prop="username"
            label="姓名"
          />
          <el-table-column
            prop="mobile"
            label="手机号"
          />
          <el-table-column
            prop="formOfEmployment"
            label="聘用形式"
            label-width="60px"
          >
            <template #default="{ row }">
              {{ formOfEmployment[row.formOfEmployment] }}
            </template>
          </el-table-column>
          <el-table-column
            prop="workNumber"
            label="部门"
          />
          <el-table-column
            prop="timeOfEntry"
            label="入职时间"
          />
          <el-table-column

            label="操作"
          >
            <el-button type="text" size="mini">查看</el-button>
            <el-button type="text" size="mini">角色</el-button>
            <el-button type="text" size="mini">删除</el-button>
          </el-table-column>
        </el-table>

        <!-- 分页 -->
        <el-pagination
          :current-page=" params.page"
          :page-size=" params.pagesize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </div>
    </div>
  </div>
</template>

<script>
import { formOfEmployment } from '@/views/employee/enum'
import { arrtree } from '@/utils/arr-tree'
import { getemployee, getpo } from '@/api/employee'

export default {
  name: 'Employee',
  data() {
    return {
      depts: [],
      defaultProps: {
        children: 'children',
        label: 'name'
      },
      list: [],
      total: 0,
      formOfEmployment: formOfEmployment,
      params: {
        pagesize: 10,
        page: 1,
        departmentId: ''
      }

    }
  },
  created() {
    this.getdepartments()
    this.getpo()
  },
  methods: {
    async getdepartments() {
      const res = await getemployee()
      this.depts = arrtree(res, 0)
    },
    async getpo() {
      const row = await getpo(this.params)
      // console.log(await getpo)
      this.list = row.rows
      this.total = row.total
    },
    setid({ id }) {
      this.params.departmentId = id
      // console.log(this.panges.departmentId)
      this.getpo()
    },
    handleSizeChange(val) {
      this.params.pagesize = val
      // console.log(this.panges.pagesize)
      this.getpo()
    },
    handleCurrentChange(val) {
      this.params.page = val
      this.getpo()
    }
  }
}
</script>

<style lang="scss" scoped>
.avator{
  width: 50px;
}
.app-container {
  background: #fff;
  display: flex;
  .left {
    width: 280px;
    padding: 20px;
    border-right: 1px solid #eaeef4;
  }
  .right {
    flex: 1;
    padding: 20px;
    .opeate-tools {
      margin:10px ;
    }
    .username {
      height: 30px;
      width: 30px;
      line-height: 30px;
      text-align: center;
      border-radius: 50%;
      color: #fff;
      background: #04C9BE;
      font-size: 12px;
      display:inline-block;
    }
  }
}

</style>
